package com.superhelper.superhelper_web.mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.superhelper.common.domain.TakeOutOrderGroup;
import com.superhelper.common.domain.TakeOutOrderProcess;
import com.superhelper.superhelper_web.domain.Order;
import com.superhelper.superhelper_web.domain.OrderGroupItem;
import com.superhelper.superhelper_web.domain.PageModel;

/**
 * 
 * @author Administrator
 *
 */

public interface OrderMapper {

	/**
	 * 
	 * @return
	 */
	List<Order> getTakeout_order(@Param("pageModel") PageModel pageModel,@Param("date_sub")Date date_sub);

	int getTakeout_orderCount(@Param("pageModel") PageModel pageModel,@Param("date_sub")Date date_sub);

	@Select("select item.*,g.type,g.name as groopName from takeout_order_group_item as item,takeout_order_group as g where g.id=item.groupId and item.orderId in(${orderIds}) ")
	List<OrderGroupItem> getTakeOutOrderGroupItem(
			@Param("orderIds") String orderIds);

	@Select("select * from takeout_order_group where orderId in(${orderIds}) ")
	List<TakeOutOrderGroup> getTakeOutOrderGroup(
			@Param("orderIds") String orderIds);

	@Select("select * from takeout_order where plfOrderId=#{orderId} and type=#{type}")
	Order getOrderByPlfOrderId(@Param("orderId") String orderId,
			@Param("type") String type);

	@Select("select * from takeout_order_process where print_state=0 and shopId in(${shopId}) and createAt<now() order by createAt asc limit 1")
	List<TakeOutOrderProcess> querOrderToPrint(@Param("shopId") String shopId);

	@Update("update takeout_order_process set print_state=2,printAt=now() where shopId in(${shopId}) and print_state!=2 and createAt<#{time}")
	int updateStatusByTime(@Param("shopId") String shopId,
			@Param("time") Date time);

	@Select("select * from takeout_order where id in(${orderIds})")
	List<Order> getOrderByIds(@Param("orderIds") String orderIds);

	@Update("update takeout_order_process set print_state=#{state},printAt=now() where orderId in(${orderIds})")
	int updateProcess(@Param("orderIds") String orderIds,
			@Param("state") Integer state);

	@Select("select * from takeout_order where id=#{orderId}")
	Order getOrderByOrderId(@Param("orderId") Long orderId);

	@Select("select * from takeout_order where status not in('settled','invalid') and createAt>date_sub(curdate(),interval 0 day)")
	List<Order> getTakeout_orderNoFinish();

	@Update("update takeout_order set status=#{status} where id=#{id}")
	int updateTakeOrderStatus(@Param("id") Long id,
			@Param("status") String status);

	@Update("update takeout_order set status = 'invalid' where plfOrderId=#{plfOrderId} and `type`=#{type}")
	int updateInvalid(@Param("plfOrderId") String plfOrderId,
			@Param("type") String type);

}
